home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 23 / Amiga Format AFCD23 (Feb 1998, Issue 107).iso / -in_the_mag- / emulation / consoles / vision-8 / sources / vdp.c < prev    next >
C/C++ Source or Header  |  1997-12-12  |  4KB  |  179 lines

  1. /****************************************************************************/
  2. /**                                                                        **/
  3. /**                                 VDP.c                                  **/
  4. /**                                                                        **/
  5. /** Routines for use with TMS9918 and compatible VDPs                      **/
  6. /**                                                                        **/
  7. /** Copyright (C) Marcel de Kogel 1997                                     **/
  8. /**     You are not allowed to distribute this software commercially       **/
  9. /**     Please, notify me, if you make any changes to this file            **/
  10. /****************************************************************************/
  11.  
  12. #include "VDP.h"
  13.  
  14. #ifdef MSX
  15. #asm
  16. VDP_CTRL_PORT   equ     99h
  17. VDP_DATA_PORT   equ     98h
  18. #endasm
  19. #else
  20. #asm
  21. VDP_CTRL_PORT   equ     0bfh
  22. VDP_DATA_PORT   equ     0beh
  23. #endasm
  24. #endif
  25.  
  26. #asm
  27.         psect   text
  28.  
  29.         global  _vdp_get_ctrl_port
  30. _vdp_get_ctrl_port:
  31.         ld      hl,VDP_CTRL_PORT
  32.         ret
  33.  
  34.         global  _vdp_get_data_port
  35. _vdp_get_data_port:
  36.         ld      hl,VDP_DATA_PORT
  37.         ret
  38.  
  39.         global  _vdp_write_ctrl
  40. _vdp_write_ctrl:
  41.         pop     hl
  42.         pop     de
  43.         ld      c,VDP_CTRL_PORT
  44.         out     (c),e
  45.         push    de
  46.         jp      (hl)
  47.  
  48.         global  _vdp_set_write_address
  49. _vdp_set_write_address:
  50.         pop     hl
  51.         pop     de
  52.         ld      c,VDP_CTRL_PORT
  53.         out     (c),e
  54.         set     6,d
  55.         out     (c),d
  56.         push    de
  57.         jp      (hl)
  58.  
  59.         global  _vdp_set_read_address
  60. _vdp_set_read_address:
  61.         pop     hl
  62.         pop     de
  63.         ld      c,VDP_CTRL_PORT
  64.         out     (c),e
  65.         nop
  66.         out     (c),d
  67.         push    de
  68.         jp      (hl)
  69.  
  70.         global  _vdp_read_data
  71. _vdp_read_data:
  72.         ld      c,VDP_DATA_PORT
  73.         in      l,(c)
  74.         ld      h,0
  75.         ret
  76.  
  77.         global  _vdp_read_status
  78. _vdp_read_status:
  79.         ld      c,VDP_CTRL_PORT
  80.         in      l,(c)
  81.         ld      h,0
  82.         ret
  83.  
  84.         global  _vdp_write_data
  85. _vdp_write_data:
  86.         pop     hl
  87.         pop     de
  88.         ld      c,VDP_DATA_PORT
  89.         out     (c),e
  90.         push    de
  91.         jp      (hl)
  92.  
  93.         global  _vdp_set_register
  94. _vdp_set_register:
  95.         pop     hl
  96.         pop     de
  97.         ld      a,e
  98.         pop     de
  99.         ld      c,VDP_CTRL_PORT
  100.         out     (c),e
  101.         set     7,a
  102.         out     (c),a
  103.         push    de
  104.         push    de
  105.         jp      (hl)
  106.  
  107.         global  _vdp_fill_video_ram
  108. _vdp_fill_video_ram:
  109.         pop     hl
  110.         exx
  111.         pop     hl
  112.         pop     de
  113.         pop     bc
  114.         ld      b,c
  115.         ld      c,VDP_CTRL_PORT
  116.         out     (c),l
  117.         set     6,h
  118.         out     (c),h
  119.         ld      c,VDP_DATA_PORT
  120. 1:      out     (c),b
  121.         dec     de
  122.         ld      a,d
  123.         or      e
  124.         jp      nz,1b
  125.         exx
  126.         push    de
  127.         push    de
  128.         push    de
  129.         jp      (hl)
  130.  
  131.         global  _vdp_write_video_ram
  132. _vdp_write_video_ram:
  133.         pop     hl
  134.         exx
  135.         pop     bc
  136.         pop     hl
  137.         pop     de
  138.         ld      a,c
  139.         ld      c,VDP_CTRL_PORT
  140.         out     (c),a
  141.         set     6,b
  142.         out     (c),b
  143.         ld      c,VDP_DATA_PORT
  144. 1:      outi
  145.         dec     de
  146.         ld      a,d
  147.         or      e
  148.         jp      nz,1b
  149.         exx
  150.         push    de
  151.         push    de
  152.         push    de
  153.         jp      (hl)
  154.  
  155.         global  _vdp_read_video_ram
  156. _vdp_read_video_ram:
  157.         pop     hl
  158.         exx
  159.         pop     bc
  160.         pop     hl
  161.         pop     de
  162.         ld      a,c
  163.         ld      c,VDP_CTRL_PORT
  164.         out     (c),a
  165.         nop
  166.         out     (c),b
  167.         ld      c,VDP_DATA_PORT
  168. 1:      ini
  169.         dec     de
  170.         ld      a,d
  171.         or      e
  172.         jp      nz,1b
  173.         exx
  174.         push    de
  175.         push    de
  176.         push    de
  177.         jp      (hl)
  178. #endasm
  179.